﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ADONetTest0001
{
    class Program
    {
        static void Main(string[] args)
        {
            
            var conString = "server=;database=Test00001;uid=sa;pwd=123456";

            SqlConnection sqlConnection = new SqlConnection(conString);

            sqlConnection.Open();//打开

            SqlCommand command = new SqlCommand("select * from UserInfo", sqlConnection);

            var reader=command.ExecuteReader();

            Console.WriteLine("{0}\t{1}\t{2}\t{3}","Id", "用户名","密码","注册日期");

            while (reader.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}\t{3}",reader["Id"], reader["UserName"], reader["UserPwd"], reader["regDate"]);
            }
            sqlConnection.Close();//关闭

            DataTable table = new DataTable();

            SqlDataAdapter dataAdapter = new SqlDataAdapter("select * from UserInfo",conString);

            dataAdapter.Fill(table);

            foreach(DataRow row in table.Rows)
            {
                Console.WriteLine(row["Id"]);
            }
            

        }
    }
}
